package sagroup.testing;

import java.util.Scanner;

import lime2.Location;
import sagroup.dracots.DracoReaction;
import sagroup.dracots.DracoReactionEvent;
import sagroup.dracots.DracoReactionListener;
import sagroup.dracots.DracoTS;
import sagroup.dracots.DracoTuple;
import sagroup.dracots.FlatShareTuple;


public class TreeReceiverAgent implements Runnable {

	DracoTS dts = null;

	@Override
	public void run() {

		try {
			dts = DracoTS.get("TreeCastTest");
			FlatShareTuple template = (FlatShareTuple) FlatShareTuple
					.createMatchAllTemplateByClass(FlatShareTuple.class);
			template.setCurr(Location.HERE);
			template.setDest(Location.UNSPECIFIED);
			template.setType(null);
			
			DracoReaction dr = new DracoReaction(DracoReaction.ONCEPERTUPLE, template, 
					new DracoReactionListener() {
						@Override
						public void reactsToWrite(DracoReactionEvent event) {
							DracoTuple t = event.getTuple();
//							System.out.println(Location.HERE + " receives the tuple " + t.getVID() + " cur:" + t.getCurr() + " dest:" + t.getDest());
						}
			});
			dts.addStrongReaction(new DracoReaction[]{dr});
			System.out.println("press ENTER to stop the agent");
			new Scanner(System.in).nextLine();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
